/*
ID:fuxiang2
PROG: gift1
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;


map<string ,int > mmap;
int getId(string name)
{
	map<string ,int > ::iterator iter = mmap.find(name);
	if(iter == mmap.end())
		return -1;

	return iter->second;
}
struct node{
	string name;
	int to;
	int from;

};
struct node array[11];

int main() {
	ofstream fout ("gift1.out");
	ifstream fin ("gift1.in");
	string a;
	string b;
	int n;
	int haved;
	int send;
	fin>>n;
	for(int i = 1 ; i<= n ; i ++){
		fin >> a;
		mmap.insert(map<string ,int >::value_type(a,i));
	}
	int ncount = 0;
	for(int i = 1 ; i <= n ; i ++){
		fin>>a;
		fin>>haved >> ncount;
		

		array[getId(a)].to = haved;
		array[getId(a)].name = a;
		if(ncount != 0)
			array[getId(a)].from += (haved - (haved/ncount)*ncount);
		for(int j = 1 ; j <= ncount ; j ++){
			fin>>b;
			array[getId(b)].from += haved/ncount;
		}
	}

	for(int i = 1 ; i <= n ; i ++)
	{
		fout<< array[i].name << " "<<(array[i].from - array[i].to) <<endl;
	}
	
	return 0;
}